using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene
{
	public class NetSceneBatchGetContactProfile : NetSceneBaseEx<BatchGetContactProfileRequest, BatchGetContactProfileResponse, BatchGetContactProfileRequest.Builder>
	{
		private const string TAG = "NetSceneBatchGetContactProfile";
		private const int MM_NEED_MODE = 0;
		private const int MM_NOT_NEED_MODE = 1;
		public bool doScene(List<string> userNameList)
		{
			Log.smethod_4("NetSceneBatchGetContactProfile", "doscene in");
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.Mode = 1u;
			this.mBuilder.Count = (uint)userNameList.get_Count();
			using (List<string>.Enumerator enumerator = userNameList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					this.mBuilder.UserNameListList.Add(Util.toSKString(current));
				}
			}
			this.mSessionPack.mCmdID = 28;
			base.endBuilder();
			return true;
		}
		protected override void onFailed(BatchGetContactProfileRequest request, BatchGetContactProfileResponse response)
		{
			Log.smethod_1("NetSceneBatchGetContactProfile", "onFailed in");
			EventCenter.postEvent(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_PROFILE_ERR, null, null);
		}
		protected override void onSuccess(BatchGetContactProfileRequest request, BatchGetContactProfileResponse response)
		{
			Log.smethod_4("NetSceneBatchGetContactProfile", "onSuccess in");
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneBatchGetContactProfile", "send BatchGetContactProfileRequest failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_PROFILE_ERR, null, null);
				return;
			}
			using (IEnumerator<SKBuiltinBuffer_t> enumerator = response.ContactProfileBufListList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					SKBuiltinBuffer_t current = enumerator.get_Current();
					ContactProfile contactProfile = ContactProfile.ParseFrom(current.Buffer.ToByteArray());
					Contact contact = new Contact();
					contact.strUsrName = contactProfile.UserName;
					contact.strNickName = contactProfile.NickName;
					contact.strAlias = contactProfile.Alias;
					contact.strPYInitial = contactProfile.PYInitial;
					contact.strQuanPin = contactProfile.QuanPin;
					contact.nSex = contactProfile.Sex;
					contact.nFlags = (contactProfile.BitMask & contactProfile.BitVal);
					contact.strRemark = contactProfile.Remark;
					contact.strRemarkPYInitial = contactProfile.RemarkPYInitial;
					contact.strRemarkQuanPin = contactProfile.RemarkQuanPin;
					contact.nContactType = contactProfile.ContactType;
					contact.strDomainList = contactProfile.DomainList;
					contact.nChatRoomNotify = contactProfile.ChatRoomNotify;
					contact.nAddContactScene = contactProfile.AddContactScene;
					contact.strExtInfo = contactProfile.ExtInfo;
					contact.nExtInfoSeq = (int)contactProfile.ExtUpdateSeq;
					contact.nImgUpdateSeq = (int)contactProfile.ImgUpdateSeq;
					StorageMgr.contact.update(contact);
				}
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_BATCH_GET_CONTACT_PROFILE_SUCCESS, null, null);
		}
	}
}
